/*
 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 * OF SUCH DAMAGE.
 *
 * This file is part of the lwIP TCP/IP stack.
 *
 * Author: Huawei Technologies
 *
 */

#ifndef __MEMP_DEF_H__
#define __MEMP_DEF_H__

#include "lwip/opt.h"
#include "arch/cc.h"

#define LWIP_MEMPOOL_BASE_DECLARE(name) \
    extern void alloc_memp_##name##_base(void);

#define LWIP_MEM_MEMORY_DECLARE(name) \
    extern void alloc_memory_##name(void);

#define LWIP_MEMPOOL_BASE_INIT(name) \
    alloc_memp_##name##_base();

#define LWIP_MEM_MEMORY_INIT(name) \
    alloc_memory_##name();

#define LWIP_MEMPOOL(name, num, size, desc) LWIP_MEMPOOL_BASE_DECLARE(name)
#include <lwip/priv/memp_std.h>
#undef LWIP_MEMPOOL

extern PER_THREAD uint8_t *ram_heap;
static inline int hugepage_init(void)
{
#define LWIP_MEMPOOL(name,num,size,desc)  LWIP_MEMPOOL_BASE_INIT(name)
#include "lwip/priv/memp_std.h"
    u16_t i;
    for (i = 0; i < LWIP_ARRAYSIZE(memp_pools); i++) {
        if (memp_pools[i]->base == NULL) {
            return -1;
        }
    }

#if !MEM_LIBC_MALLOC
	LWIP_MEM_MEMORY_DECLARE(ram_heap)
    LWIP_MEM_MEMORY_INIT(ram_heap)
    if (ram_heap == NULL) {
        return -1;
    }
#endif /* MEM_LIBC_MALLOC */
    return 0;
}

#endif /* __MEMP_DEF_H__ */
